/**
 * @author Nick Davis
 * @version 1.0
 * @date 10-23-12 
 */

package net.jetpack.notecards;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.TextView;

public class MainActivity extends Activity implements OnGestureListener {
	private GestureDetector gDetector;
	String[] termsTest;
	String[] defsTest;
	int termNumber = 0;
	boolean DEBUG = false;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gDetector = new GestureDetector(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    //@Override
    public boolean onDown(MotionEvent arg0) {
        // TODO display next term
    	
    	if (DEBUG) {
			TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onDown");
		}
        return false;
    }
    
    //@Override
    public boolean onFling(MotionEvent start, MotionEvent finish, float xVelocity, float yVelocity) {
        if (start.getRawY() < finish.getRawY()) {
        	// TODO display definition
        	defsTest = getResources().getStringArray(R.array.definitionArray);
        	TextView text1 = (TextView) findViewById(R.id.text1);
        	text1.setText(defsTest[termNumber]);
        	
        } else {
        	// TODO display term
        	termsTest = getResources().getStringArray(R.array.termArray);
        	TextView text1 = (TextView) findViewById(R.id.text1);
        	text1.setText(termsTest[termNumber]);
        }
        
        if (DEBUG) {
        	TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onFling");        	
        }
        return true;
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent me) {
    	return gDetector.onTouchEvent(me);
    }

	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
		if (DEBUG) {
			TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onLongPress");
		}
	}

	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub	
		
		if (DEBUG) {
			TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onScroll");
		}
		return false;
	}

	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub
		
		if (DEBUG) {
			TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onShowPress");
		}
	}

	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		if ( termNumber >= 170 ) { 
			termNumber = 0; 
		} else {
			termNumber++;
		}	
		
		termsTest = getResources().getStringArray(R.array.termArray);
    	TextView text1 = (TextView) findViewById(R.id.text1);
    	text1.setText(termsTest[termNumber]);
		
		if (DEBUG) {
			TextView text2 = (TextView) findViewById(R.id.text2);
	    	text2.setText("onSingleTapUp");
		}
		return false;
	}		
}
